package module.main.view.mainInterface.troopListPanel
{
	import com.darwin.darwinUI.controls.Button;
	import com.darwin.darwinUI.controls.IListItem;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.TextFieldFactory;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	
	import module.edittroop.model.dataObj.HeroConfigObj;
	import module.main.event.MainEvent;
	import module.main.view.ResourceConst;
	import module.scene.model.dataObj.TroopIsoDataObj;
	
	/**
	 * 部队列表项
	 * @author killsoon
	 */	
	public class TroopListItem extends UIComponent implements IListItem
	{
		private var heroImage:UIComponent;
		private var heroName:Label;
		private var troopName:Label;
		private var troopNum:Label;
		private var btSelectArea:Button;
		private var gou:UIComponent;
		private var selectedBg:UIComponent;
		private var mouseSprite:UIComponent;
		
		private var gouIsVisiable:Boolean = false;
		
		public function TroopListItem()
		{
			super();
			initView();
			initListener();
		}
		
		private function initView():void
		{
			this.width = 125;
			this.height = 41;
			selectedBg = new UIComponent();
			selectedBg.backgroundSkin = ResourceConst.FRIENDLIST_SELECTED_BG;
			selectedBg.backgroundAuto  = true;
			addChild(selectedBg);
			selectedBg.visible = false;
			
			mouseSprite = new UIComponent();
			mouseSprite.graphics.beginFill(0xffffff);
			mouseSprite.graphics.drawRect(0, 0, 125, 41);
			mouseSprite.graphics.endFill();
			mouseSprite.alpha = 0;
			addChild(mouseSprite);
			
			heroImage = new UIComponent();
			heroImage.backgroundSkin = ResourceConst.HERO_IAMGE;
			heroImage.backgroundAuto = true;
			heroImage.x = 6;
			heroImage.y = 3;
			heroImage.buttonMode = true;
			addChild(heroImage);
			
			heroName = new Label();
//			heroName = TextFieldFactory.getInstance().getLabel("ForceList_hero_name");
			heroName.x = 45;
			heroName.y = 3;
			heroName.textColor = 0xffffff;
			addChild(heroName);
			
			troopName = new Label();
//			troopName = TextFieldFactory.getInstance().getLabel("formation_arms_typeName");
			troopName.x = 45;
			troopName.y = 20;
			troopName.textColor = 0xffffff;
			addChild(troopName);
			
			troopNum = new Label();
//			troopNum = TextFieldFactory.getInstance().getLabel("formation_hero_troops_number");
			troopNum.x = 88;
			troopNum.y = 20;
			troopNum.textColor = 0xffffff;
			addChild(troopNum);
			
			btSelectArea = new Button();
			btSelectArea.backgroundSkin = ResourceConst.SELECT_AREA_BUTTON;
			btSelectArea.backgroundAuto = true;
			btSelectArea.x = 109;
			btSelectArea.y = 1;
			addChild(btSelectArea);
			
			gou = new UIComponent();
			gou.backgroundSkin = ResourceConst.GOU;
			gou.backgroundAuto = true;
			gou.x = -2;
			gou.y = -5;
			btSelectArea.addChild(gou);
			
			gou.visible = false;
		}
		
		private function initListener():void
		{
			heroImage.addEventListener(MouseEvent.CLICK, clickHandler);
			btSelectArea.addEventListener(MouseEvent.CLICK, clickHandler);
			addEventListener(MouseEvent.ROLL_OVER, rollOverItem);
			addEventListener(MouseEvent.ROLL_OUT, rollOutItem);
		}
		
		private function rollOverItem(e:MouseEvent):void
		{
			selectedBg.visible = true;
		}
		
		private function rollOutItem(e:MouseEvent):void
		{
			selectedBg.visible = false;
		}
		
		private function clickHandler(e:MouseEvent):void
		{
			switch(e.currentTarget)
			{
				case heroImage:
					heroImageClick();
					break;
				case btSelectArea:
					showOrHideGou();
					break;
				default:
					break;
				
			}
		}
		
		private function heroImageClick():void
		{
			var mainEvent:MainEvent = new MainEvent(MainEvent.CLICK_HERO_IMAGE_EVENT);
			mainEvent.data = data;
			dispatchEvent(mainEvent);
		}
		
		private function showOrHideGou():void
		{
			if(!gouIsVisiable)
			{
				gou.visible = true;
				gouIsVisiable = true;
			}
			else
			{
				gou.visible = false;
				gouIsVisiable = false;
			}
		}
		
		public function set selected(v:Boolean):void
		{
			
		}
		
		public function get selected():Boolean
		{
			return false;
		}
		
		private var _data:Object;
		
		public function get data():Object
		{
			return _data;
		}
		
		public function set data(v:Object):void
		{
			_data = v;
			var troopIsoObjectObj:TroopIsoDataObj = _data as TroopIsoDataObj;
			heroName.text = "费董平";
//			heroName.text = UIManager.getLanguageManager().getText("ForceList_hero_name", ["必胜"]);
			troopName.text = "弓箭手:";
			troopNum.text = "15000";
//			heroName.text = troopIsoObjectObj.heroObj.name;
//			troopName.text = troopIsoObjectObj.armsObj.name;
//			troopNum.text = troopIsoObjectObj.troopNum.toString();
		}
		
		public function get index():int
		{
			return 0;
		}
		
		public function set index(v:int):void
		{
		}
		
		public function dispose():void
		{
		}
	}
}